package bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import oracle.jdbc.pool.OracleDataSource;

public class Pengiriman {

    private String kodePengiriman;
    private String waktuPengiriman;
    private String kodePemesanan;
    private String username;
    private int jumlahBarang;
    private String idBarang;
    private double hargaBarang;
    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "mhs115314034"; // gantikan dengan username anda
    String pass = "mhs115314034"; // gantikan dengan password anda

    public String getKodePengiriman() {
//        try {
//            Connection connection = null;
//            OracleDataSource ds;
//            ds = new OracleDataSource();
//            ds.setURL(jdbcUrl);
//            ds.setPassword(pass);
//            ds.setUser(userid);
//            connection = (Connection) ds.getConnection();
//            Statement statement = connection.createStatement();
//            ResultSet resultSet = statement.executeQuery("select kodepengiriman from pengiriman order by kodepengiriman");
//            String kode_penerimaan = "";
//            Date now = new Date();
//            SimpleDateFormat dateFormatterTanggal = new SimpleDateFormat("d");
//            SimpleDateFormat dateFormatterBulan = new SimpleDateFormat("M");
//            SimpleDateFormat dateFormatterTahun = new SimpleDateFormat("y");
//            String tanggal = dateFormatterTanggal.format(now);
//            String bulan = dateFormatterBulan.format(now);
//            String tahun = dateFormatterTahun.format(now);
//            String substring = tahun.substring(2);
//            String kodeTanggal = tanggal+bulan+substring;
//            while (resultSet.next()) {
//                kode_penerimaan = resultSet.getString("kodepengiriman");
//            }
//            int no_penerimaan = 0;
//            if ("".equals(kode_penerimaan)) {
//                this.kodePengiriman = kodeTanggal + "001";
//            } else {
//                String data = kode_penerimaan.substring(0, 6);
//                if (kodeTanggal.equals(data)) {
//                    no_penerimaan = Integer.parseInt(kode_penerimaan) + 1;
//                    this.kodePengiriman = String.valueOf(no_penerimaan);
//                } else {
//                    this.kodePengiriman = kodeTanggal + "001";
//                }
//            }
//        } catch (SQLException e) {
//// perform error handling here
//            System.out.println("error :" + e.getMessage());
//            this.kodePengiriman = null;
//        }
        return kodePengiriman;

    }

    public String getWaktuPengiriman() {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("d-M-y");
        this.waktuPengiriman = simpleDateFormat.format(date);
        return waktuPengiriman;
    }

  

    public void setKodePengiriman(String kodePengiriman) {
        this.kodePengiriman = kodePengiriman;
    }
    public String getKodePemesanan() {
        return kodePemesanan;
    }

    public void setKodePemesanan(String kodePemesanan) {
        this.kodePemesanan = kodePemesanan;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getJumlahBarang() {
        return jumlahBarang;
    }

    public void setJumlahBarang(int jumlahBarang) {
        this.jumlahBarang = jumlahBarang;
    }

    public String getIdBarang() {
        return idBarang;
    }

    public void setIdBarang(String idBarang) {
        this.idBarang = idBarang;
    }

    public double getHargaBarang() {
        return hargaBarang;
    }

    public void setHargaBarang(double hargaBarang) {
        this.hargaBarang = hargaBarang;
    }

     public ResultSet tampilBarang() {
        try {
            Connection connection = null;
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            ds.setPassword(pass);
            ds.setUser(userid);
            connection = (Connection) ds.getConnection();
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("select * from pengiriman");
            String hasil[] = null;
            int counter = 0;
            return resultSet;
        } catch (SQLException e) {
// perform error handling here
            System.out.println("error :" + e.getMessage());
            return null;
        }
    }
}
